{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Queue - Provides thread safe FIFO implementation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 1 2 3 4 5 6 7 8 9 "
     ]
    }
   ],
   "source": [
    "#Basic fifo queue - the usual queue all are familiar with!\n",
    "\n",
    "import queue\n",
    "\n",
    "q = queue.Queue()\n",
    "\n",
    "for i in range(10):\n",
    "    q.put(i)\n",
    "    \n",
    "while not q.empty():\n",
    "    print(q.get(), end = ' ')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9 8 7 6 5 4 3 2 1 0 "
     ]
    }
   ],
   "source": [
    "# LIFO queue - LIFO is usually is associated with Stack!\n",
    "\n",
    "lifoq = queue.LifoQueue()\n",
    "\n",
    "for i in range(10):\n",
    "    lifoq.put(i)\n",
    "    \n",
    "while not lifoq.empty():\n",
    "    print(lifoq.get(), end = ' ')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Priority queue \n",
    "\n",
    "pq = queue.PriorityQueue()\n",
    "pq.put((10, 'tom'))\n",
    "pq.put((5, 'jerry'))\n",
    "pq.put((1, 'ray'))\n",
    "pq.put((3, 'ajax'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1, 'ray')\n",
      "(3, 'ajax')\n",
      "(5, 'jerry')\n",
      "(10, 'tom')\n"
     ]
    }
   ],
   "source": [
    "#maintains queue in order of priority\n",
    "while not pq.empty():\n",
    "    print(pq.get())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
